package com.nny.demo141;

import jdk.internal.icu.impl.CharacterIteratorWrapper;

import java.sql.*;
import java.util.Scanner;

public class LoginDemo {
    private static final String URL = "JDBC:mysql://localhost:3306/usersDb";
    private static  final String DB_USERNAME = "root";
    private static final String DB_PASSWORD = "123456";

    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.jdbc.Driver");
        Connection conn = DriverManager.getConnection(URL, DB_USERNAME, DB_PASSWORD);
        String sql = "select * from users where username=? and password=?";
        PreparedStatement preparedStatement = conn.prepareStatement(sql);
        Scanner  scanner = new Scanner(System.in);
        System.out.println("请输入用户名");
        String username= scanner.next();
        System.out.println("请输入密码");
        String password= scanner.next();
        preparedStatement.setString(1,username);
        preparedStatement.setString(2,password);
        ResultSet resultSet = preparedStatement.executeQuery();
        if(resultSet.next()){
            System.out.println("登录成功");
        }
        else{
            System.out.println("失败");
        }
        }
        }
